package com.iu.control;

import com.google.gson.Gson;
import com.iu.bean.NoteBean;
import com.iu.dao.NoteDao;
import com.iu.dao.UserDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/getAllNote")
public class GetAllNoteServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        UserDao userDao=new UserDao();
        NoteDao noteDao=new NoteDao();
        Gson gson=new Gson();

        String tel=request.getParameter("phone");
        List<NoteBean> list=noteDao.queryNote(userDao.getIdByTel(tel));//为防止信息泄露 在此user_id与id未从数据库中保存，如需要后期再加 。发现任务7需要，现在把id赋值
        String res=gson.toJson(list);
        response.getWriter().append(res);
    }
}
